package com.hd.crdao.activity;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.widget.FrameLayout;
import android.widget.RadioGroup;

import com.hd.crdao.R;
import com.hd.crdao.base.BaseActivity;
import com.hd.crdao.fragment.QueryFrangment;
import com.hd.crdao.fragment.ReportFrangment;
import com.hd.crdao.fragment.SetMealFrangment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 *
 *@author Administrator
 *@date 2017/6/26 0026
 */
public class RepairQueryActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener {
    @BindView(R.id.fragment_container)
    FrameLayout mFragmentContainer;
    @BindView(R.id.rg_menu)
    RadioGroup mRgMenu;
    List<Fragment> mFragments = new ArrayList<>();
    public Fragment mQueryFrangment;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_repairquery;
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        mQueryFrangment = new QueryFrangment();
        mFragments.add(mQueryFrangment);
        mFragments.add(new ReportFrangment());
        mFragments.add(new SetMealFrangment());
    }

    @Override
    protected void initListener() {
        mRgMenu.setOnCheckedChangeListener(this);
    }

    @Override
    protected void initData() {
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.fragment_container,mQueryFrangment);
        fragmentTransaction.commit();

    }


    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        switch (checkedId){
            case R.id.rb_query:
                ft.replace(R.id.fragment_container,mFragments.get(0));
                break;
            case R.id.rb_report:
                ft.replace(R.id.fragment_container,mFragments.get(1));
                break;
            case R.id.rb_setmeal:
                ft.replace(R.id.fragment_container,mFragments.get(2));
                break;
        }
        ft.commit();
    }
}
